<template>
  <div class="shop">
    <el-button size='small'
      class='addstaffrole'
      type="primary"
      @click="showAddRole= true">新增员工角色</el-button>
    <el-table :data="tableData"
      style="width:100%"
      max-height="680"
      :cell-style="tc"
      :header-cell-style="tccolor">
      <el-table-column label='角色ID'
        prop='id'></el-table-column>
      <el-table-column label='角色名称'
        prop='name'></el-table-column>
      <el-table-column label='角色描述'
        prop='desc'></el-table-column>
      <el-table-column label='适用范围'
        prop='range'></el-table-column>
      <el-table-column label='操作'
        fixed='right'
        width='160'>
        <template slot-scope="scope">
          <el-button size='mini'
            @click="openRoleDetail(scope.row.id)">详情</el-button>
          <el-button size='mini'
            type='primary'
            @click="deleteRole(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- @size-change="handleSizeChange" -->
    <el-col :span="24">
      <div class="pagination">
        <el-pagination background
          @current-change="pageChange"
          :current-page="page"
          :page-size="size"
          layout="total, prev, pager, next, jumper"
          :total="total"></el-pagination>
      </div>
    </el-col>

    <!--新增角色-->
    <jdialog title="新增角色"
      :visible.sync="showAddRole"
      width="720px">
      <el-form ref="form"
        :model="form"
        :rules="rules"
        class="addrole">
        <el-form-item label='新增角色名称'
          prop='name'>
          <el-input size='mini'
            v-model="form.name"
            class="input"
            clearable></el-input>
        </el-form-item>
        <el-form-item label="适用范围"
          prop="region">
          <el-select size = 'mini' v-model="form.region"
            placeholder="请选择适用范围">
            <el-option  v-for="(item,index) in regionList" :label="item.name"
              :value="item.id" :key="index"></el-option>
          </el-select>
        </el-form-item>
       <el-form-item label='角色描述'
          prop='desc'>
          <el-input size='mini'
            v-model="form.desc"
            maxlength="24"
            show-word-limit
            class="input"
            clearable></el-input>
        </el-form-item>
      <el-form-item label='角色授权' prop='role'>
        <!-- <el-checkbox-group v-model="form.role"> -->
         <div class="active-title">活动管理</div>
      <el-checkbox label="活动创建" name="role"></el-checkbox>
      <el-checkbox label="活动数据查看" name="role"></el-checkbox>
      <br/>
      <div class="active-title active_subtitle">爆品管理</div>
      <el-checkbox label="爆品创建" name="role"></el-checkbox>
      <el-checkbox label="爆品数据查看" name="role"></el-checkbox>
      <br/>
      <div class="active-title active_subtitle">现金券</div>
      <el-checkbox label="现金券创建" name="role"></el-checkbox>
      <el-checkbox label="现金券数据查看" name="role"></el-checkbox>
      <br/>
      <div class="active-title active_subtitle">满减券</div>
      <el-checkbox label="满减券创建" name="role"></el-checkbox>
      <el-checkbox label="满减券数据查看" name="role"></el-checkbox>
      <br/>
      <div class="active-title active_subtitle">核销</div>
      <el-checkbox label="券码核销" name="role"></el-checkbox>
    <!-- </el-checkbox-group> -->
      </el-form-item>
      </el-form>
      <div class="class_btn">
        <el-button size="mini"
          type="primary"
          @click="showAddRole = false">确定</el-button>
        <el-button size="mini"
          @click="certainAddStaffRole">取消</el-button>
      </div>
    </jdialog>
  </div>
</template>

<script>
export default {
  data () {
    return {

      showAddRole: false,
      regionList: [{'name':'系统全局','id':'1'},{'name':'丽人美发','id':'2'},{'name':'水果生鲜','id':'3'}],
      form: {
        name: '',
        region:'',
        desc:'',
        role:''
      },
      rules: {
        name: [
          { required: true, message: '请输入角色名称', trigger: 'blur' },
          { min: 2, max: 15, message: '长度在 2 到 15 个字符', trigger: 'blur' }
        ],
        region: [
            { required: true, message: '请选择适用范围', trigger: 'change' }
          ],
        desc: [
          { required: true, message: '请输入角色描述', trigger: 'blur' },
          { min: 1, max: 24, message: '长度在 1 到 24 个字符', trigger: 'blur' }
        ],
        role: [
            { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
          ],
      },
      page: 1,
      size: 10,
      total: 0,
      tableData: [{ 'id': '10001', 'name': '普通员工', 'desc': '不具有收益查看权限', 'range': '全局' }, { 'id': '10001', 'name': '店长经理', 'desc': '不具有收益查看权限', 'range': '生鲜水果' }, { 'id': '10001', 'name': '小店实习生', 'desc': '不具有收益查看权限', 'range': '美食小吃 | 丽人美发' }]
    }
  },
  mounted () {

  },
  methods: {
    openRoleDetail (id) {
      console.log(id)
    },
    deleteRole (id) {
      this.$confirm("确定删除该角色?", "温馨提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        //删除员工角色
        console.log(id)
      });
    },
    pageChange (page) {
      this.page = page
      //获取数据
    },

    certainAddStaffRole () {
      //新增角色，成功后刷新界面
      this.showAddRole = false
    },
    tc () {
      return "text-align:center; color:#333333; font-size:12px;";
    },
    tccolor () {
      return "text-align:center;background-color:#f5f5f5; font-size:14px;";
    },
  }
}
</script>

<style lang="scss" scoped>
.shop {
  padding: 20px;
  .addstaffrole {
    float: right;
    margin-bottom: 20px;
  }
  .pagination {
    float: right;
    margin-top: 15px;
  }
  .addrole {
    padding: 10px 60px;
  }
  .class_btn {
    margin-top: 20px;
    margin-bottom: 20px;
    text-align: center;
  }
  .input {
    width: 380px;
  }
  .active-title{
    float: left;
    width: 100px;
    height: 28px;
    background-color: #f5f5f5;
    text-align: center;
    line-height: 28px;
    color: #666666;
    margin: 5px 12px;
  }
  .active_subtitle{
    margin: 5px 12px 5px 90px;
  }
}
</style>
